﻿using System;
using System.Collections.Generic;
using System.Web.Services;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Adex;
using Telerik.Web.UI;
using MediaMonitor.Common;
using System.Web.Security;
using System.Configuration;
using Ionic.Zip;
using System.IO;
using Aspose.Slides.Pptx;
using Aspose.Slides.Export;
using PPTUtilities;
using System.Reflection;
using System.Drawing;
using System.Linq;
using System.Text;
namespace MediaMonitor.Users
{
    public partial class Report_All_Filter : Adex.BasePage
    {

        DateTime sDate = DateTime.MinValue, eDate = DateTime.MinValue;
        private int mediaTypeCode = 0;
        private string mediaCodes_TV = "";
        private string mediaCodes_Radio = "";
        private string mediaCodes_Cable = "";
        private string mediaCodes_Press = "";
        private string mediaCodes_Outdoor = "";
        private string mediaCodes_Internet = "";
        private string mediaTypeCodes = "";
        private string mediaCodes_Competition = "";

        private int programCode = 0;
        private string sectorCode = "", subSectorCode = "", subSector2Code = "", categoryCode = "";
        string advertiserCode = "", brandCode = "", productCode = "", versionCode = "", agencyCode = "";
        int sTime = 0, eTime = 0;
        int sLength = 0, eLength = 0;
        int posInBreak = 0;
        int sPrice = 0, ePrice = 0;
        bool firstAppearanceOnly = false;
        bool DownloadOnly = false;
        bool DownloadOnlyProduct = false;
        bool DownloadOnlyAdvertiser = false;
        List<TextProperties> lstProp = null;
        List<TextProperties> lstProp1 = null;
        Dictionary<string, int> screenPos = new Dictionary<string, int>();
        DataTable tvTable = null;
        DataTable cableTable = null;
        DataTable countryRadioTable = null;
        DataTable pressTable = null;
        DataTable outdoorTable = null;
        DataTable countyOutdoorTable = null;
        DataTable radioTable = null;
        DataTable internetTable = null;

        DataTable advertiserTable = null;
        DataTable dowTable = null;
        DataTable weeksTable = null;
        DataTable versionTable = null;
        DataTable newTable = null;
        DataTable templateTable = null;
        string pptFilePath = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                PremissionForModules();
                Utility.AddDateControlToPage(this.Page);
                SetCalendarDates();


                FillMediaTypes();

                FillSectors();
                FillSubSectors();
                FillCategories();
                FillAdvertisers();
                FillAgencies();

                Session["UserWriteProductName"] = "";
                Session["SearchMediaCodes_Competition"] = "";
                GetLatestRecords();


            }
        }


        private void GetLatestRecords()
        {
            DataTable dt = RfController.GetLastAvailable_All();
            if (dt.Rows.Count > 0)
            {
                lblTVMax.Text = dt.Rows[0][0].ToString();
                lblRadioMax.Text = dt.Rows[0][0].ToString();
                lblCableMax.Text = dt.Rows[0][0].ToString();
                lblCountryMax.Text = dt.Rows[0][0].ToString();
                lblPressMax.Text = dt.Rows[1][0].ToString();
                lblOutdoorMax.Text = dt.Rows[3][0].ToString();
                lblInternetMax.Text = dt.Rows[2][0].ToString();
                lblCountrySideOutDoor.Text = dt.Rows[3][0].ToString();

            }

        }


        private void PremissionForModules()
        {

            String UserID = String.Empty;
            String ReturnValue = String.Empty;

            MembershipUser memUsr = System.Web.Security.Membership.GetUser();
            if (memUsr != null)
            {
                UserID = memUsr.ProviderUserKey.ToString();
            }
            ReturnValue = RfController.GetSiteUsers_ModuleStatusAll(UserID);

            string[] value = ReturnValue.Split(',');

            for (int i = 0; i < value.Length; i++)
            {
                switch (value[i])
                {
                    case "1":
                        trMedia_TV.Visible = true;
                        chkAll_TV.Checked = true;
                        break;
                    case "3":
                        trMedia_Radio.Visible = true;
                        chkAll_Radio.Checked = true;
                        break;
                    case "5":
                        trMedia_Cable.Visible = true;
                        chkAll_Cable.Checked = true;
                        break;
                    case "6":
                        trMedia_Press.Visible = true;
                        chkAll_Press.Checked = true;
                        break;
                    case "7":
                        trMedia_OutDoor.Visible = true;
                        chkAll_OutDoor.Checked = true;

                        if (AppUser.GetCountry() == 58)
                        { }
                        else
                        {
                            trMedia_OutDoor.Visible = false;
                        }
                        break;
                    case "9":
                        if (ReturnValue.Contains(9.ToString())) //Internet
                        {
                            tr1.Visible = true;
                            chkAll_Internet.Checked = true;
                        }
                        break;
                    case "11":
                        trMedia_CountrySide.Visible = true;
                        chkAll_Country.Checked = true;
                        break;
                    case "12":
                        trCountrySideOutDoor.Visible = true;
                        chkAll_CountrySideOutDoor.Checked = true;
                        break;
                }
            }

            //    if (ReturnValue.Contains(1.ToString())) //TV
            //    {
            //        trMedia_TV.Visible = true;
            //        chkAll_TV.Checked = true;
            //    }

            //if (ReturnValue.Contains(3.ToString())) //Radio
            //{
            //    trMedia_Radio.Visible = true;
            //    chkAll_Radio.Checked = true;
            //}

            //if (ReturnValue.Contains(5.ToString())) //Cable
            //{
            //    trMedia_Cable.Visible = true;
            //    chkAll_Cable.Checked = true;
            //}

            //if (ReturnValue.Contains(6.ToString())) //Press
            //{
            //    trMedia_Press.Visible = true;
            //    chkAll_Press.Checked = true;
            //}

            //if (ReturnValue.Contains(7.ToString())) //OUTDOOR
            //{
            //    trMedia_OutDoor.Visible = true;
            //    chkAll_OutDoor.Checked = true;

            //    if (AppUser.GetCountry() == 58)
            //    { }
            //    else
            //    {
            //        trMedia_OutDoor.Visible = false;
            //    }

            //}

            //if (ReturnValue.Contains(9.ToString())) //Internet
            //{
            //    tr1.Visible = true;
            //    chkAll_Internet.Checked = true;
            //}


        }

        private void SetCalendarDates()
        {


            DataTable dtTVCR = CommercialLog1.Query().DISTINCT().SetSelectList("RFDate").ExecuteDataSet().Tables[0];
            DataTable dtPR = PressLog.Query().DISTINCT().SetSelectList("RFDate").ExecuteDataSet().Tables[0];
            DataTable dtOD = OutdoorLog.Query().DISTINCT().SetSelectList("RFDate").ExecuteDataSet().Tables[0];

            DataTable dtIN = InternetLog.Query().DISTINCT().SetSelectList("RFDate").ExecuteDataSet().Tables[0];

            List<DateTime> dates = new List<DateTime>();

            foreach (DataRow dr in dtTVCR.Rows)
            {
                if (dr["RFDate"].ToString() != "")
                    dates.Add(Utility.ToDateTime(Utility.GetDateFromNumber(dr["RFDate"].ToString())));
            }
            foreach (DataRow dr in dtPR.Rows)
            {
                dates.Add(Utility.ToDateTime(dr["RFDate"]));
            }
            foreach (DataRow dr in dtOD.Rows)
            {
                dates.Add(Utility.ToDateTime(dr["RFDate"]));
            }

            foreach (DataRow dr in dtIN.Rows)
            {
                dates.Add(Utility.ToDateTime(dr["RFDate"]));
            }

            foreach (DateTime dt in dates)
            {

                RadCalendarDay d1 = new RadCalendarDay(calS);
                d1.Date = dt;
                d1.IsDisabled = false;
                d1.IsSelectable = true;

                d1.ItemStyle.BackColor = System.Drawing.Color.PowderBlue;
                d1.ItemStyle.ForeColor = System.Drawing.Color.White;

                calS.SpecialDays.Add(d1);

                RadCalendarDay d2 = new RadCalendarDay(calE);
                d2.Date = dt;
                d2.IsDisabled = false;
                d2.IsSelectable = true;

                d2.ItemStyle.BackColor = System.Drawing.Color.PowderBlue;
                d2.ItemStyle.ForeColor = System.Drawing.Color.White;


                calE.SpecialDays.Add(d2);
            }



        }


        protected void calS_ViewChanged(object sender, EventArgs e)
        {
            for (DateTime dt = calS.CalendarView.ViewStartDate; dt <= calS.CalendarView.ViewEndDate; dt.AddDays(1))
            {

            }
        }

        private static DataSet GetLookupDataSet()
        {
            //if (HttpRuntime.Cache["dsLookUpByUser_ALL_" + AppUser.CurrUserID.ToString()] == null)
            if (HttpContext.Current.Cache["dsLookUpByUser_ALL_" + AppUser.CurrUserID.ToString()] == null)
            {
                //Get Lookup Tables filtered by User / Company settings

                //DataSet ds = SPs.SpGetReportFilterLookupTables(AppUser.CurrUserID).GetDataSet();
                DataSet ds = SPs.GetLookupTables(AppUser.CurrUserID, "ALL").GetDataSet();
                ds.Tables[0].TableName = "MediaType";
                ds.Tables[1].TableName = "Media";
                ds.Tables[2].TableName = "Agency";
                ds.Tables[3].TableName = "Advertiser";
                ds.Tables[4].TableName = "Brand";
                ds.Tables[5].TableName = "Sector";
                ds.Tables[6].TableName = "SubSector";
                ds.Tables[7].TableName = "Category";
                ds.Tables[8].TableName = "Product";
                ds.Tables[9].TableName = "ProdVersion";
                //ds.Tables[10].TableName = "Program";

                HttpContext.Current.Cache.Insert("dsLookUpByUser_ALL_" + AppUser.CurrUserID.ToString(), ds, null, DateTime.Now.AddMinutes(60), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);

                HttpRuntime.Cache.Insert("dsLookUpByUser_ALL_" + AppUser.CurrUserID.ToString(), ds, null, DateTime.Now.AddMinutes(60), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
                return ds;

            }
            else
            {
                return ((DataSet)(HttpContext.Current.Cache["dsLookUpByUser_ALL_" + AppUser.CurrUserID.ToString()]));
                //    return ((DataSet)(HttpRuntime.Cache["dsLookUpByUser_ALL_" + AppUser.CurrUserID.ToString()]));
            }
        }


        #region FillLists


        private void FillSectors()
        {
            DataTable dt = GetLookupDataSet().Tables[5];
            DataView dv = dt.DefaultView;
            dt = dv.ToTable(true, "SectorName");

            lstSector.DataSource = dt;
            lstSector.DataBind();

            lstSector.Items.Insert(0, new ListItem("- ALL -", ""));
        }

        private void FillSubSectors()
        {
            DataTable dt = GetLookupDataSet().Tables[6];

            string filter = "";
            filter += lstSector.SelectedValue != "" ? "SectorName='" + lstSector.SelectedValue + "'" : "";

            string sort = "SubSectorName";

            DataView dv = new DataView(dt, filter, sort, DataViewRowState.OriginalRows);



            dt = dv.ToTable(true, "SubSectorName");

            lstSubSector.DataSource = dt;
            lstSubSector.DataBind();

            lstSubSector2.DataSource = dt;
            lstSubSector2.DataBind();

            lstSubSector.Items.Insert(0, new ListItem("- ALL -", ""));
            lstSubSector2.Items.Insert(0, new ListItem("- ALL -", ""));
        }

        private void FillCategories()
        {
            DataTable dt = GetLookupDataSet().Tables[7];

            string filter = "1=1 ";
            filter += lstSector.SelectedValue != "" ? " AND SectorName='" + lstSector.SelectedValue + "'" : "";
            filter += lstSubSector.SelectedValue != "" ? " AND SubSectorName='" + lstSubSector.SelectedValue + "'" : "";

            string sort = "CategoryName";

            DataView dv = new DataView(dt, filter, sort, DataViewRowState.OriginalRows);

            dt = dv.ToTable(true, "CategoryName");

            lstCategory.DataSource = dt;
            lstCategory.DataBind();
            lstCategory.Items.Insert(0, new ListItem("- ALL -", ""));
        }

        private void FillAdvertisers()
        {
            DataTable dt = GetLookupDataSet().Tables[3];
            lstAdvertiser.DataSource = dt;
            lstAdvertiser.DataBind();

            lstAdvertiser.Items.Insert(0, new ListItem("- ALL -", ""));
        }

        private void FillAgencies()
        {
            DataTable dt = GetLookupDataSet().Tables[2];

            DataView dv = dt.DefaultView;
            dv.RowFilter = "AgencyName IS NOT NULL AND AgencyName <> ''";

            dt = dv.ToTable(true, "AgencyName");

            lstAgency.DataSource = dt;
            lstAgency.DataBind();
            lstAgency.Items.Insert(0, new ListItem("- ALL -", ""));
        }

        protected void lstSector_Changed(object sender, EventArgs e)
        {
            FillSubSectors();
            FillCategories();
            // pnlUpdate_ReportAllFilters.Update();
        }

        protected void lstSubSector_Changed(object sender, EventArgs e)
        {
            FillCategories();
            //pnlUpdate_ReportAllFilters.Update();
        }

        #endregion


        #region AutoComplete Functions

        [WebMethod]
        public static string[] AutoComplete_FillSectors(string prefixText, int count)
        {
            if (count == 0) { count = 10; }
            List<string> items = new List<string>(count);

            DataTable dt = GetLookupDataSet().Tables[5];

            DataRow[] drs = dt.Select("SectorName LIKE '%" + prefixText + "%'");

            int counter = 0;
            foreach (DataRow dr in drs)
            {
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["SectorName"].ToString(), dr["SectorName"].ToString()));


                if (++counter >= count) { break; }
            }

            return items.ToArray();
        }


        [WebMethod]
        public static string[] AutoComplete_FillSubSector(string prefixText, int count)
        {
            if (count == 0) { count = 10; }
            List<string> items = new List<string>(count);

            DataTable dt = GetLookupDataSet().Tables[6];

            DataRow[] drs = dt.Select("SubSectorName LIKE '%" + prefixText + "%'");

            int counter = 0;
            foreach (DataRow dr in drs)
            {
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["SubSectorName"].ToString(), dr["SubSectorName"].ToString()));


                if (++counter >= count) { break; }
            }

            return items.ToArray();
        }


        [WebMethod]
        public static string[] AutoComplete_FillCategories(string prefixText, int count)
        {
            if (count == 0) { count = 10; }
            List<string> items = new List<string>(count);

            DataTable dt = GetLookupDataSet().Tables[7];

            DataRow[] drs = dt.Select("CategoryName LIKE '%" + prefixText + "%'");

            int counter = 0;
            foreach (DataRow dr in drs)
            {
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["CategoryName"].ToString(), dr["CategoryName"].ToString()));


                if (++counter >= count) { break; }
            }

            return items.ToArray();
        }


        [WebMethod]
        public static string[] AutoComplete_FillAdvertiser(string prefixText, int count)
        {
            if (count == 0) { count = 10; }
            List<string> items = new List<string>(count);

            DataTable dt = GetLookupDataSet().Tables[3];

            DataRow[] drs = dt.Select("AdvertiserName LIKE '%" + prefixText + "%'");

            int counter = 0;
            foreach (DataRow dr in drs)
            {
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["AdvertiserName"].ToString(), dr["AdvertiserName"].ToString()));


                if (++counter >= count) { break; }
            }

            return items.ToArray();
        }

        [WebMethod(EnableSession = true)]
        public static string[] AutoComplete_FillBrand(string prefixText, int count)
        {
            if (count == 0) { count = 10; }
            List<string> items = new List<string>(count);

            DataTable dt = GetLookupDataSet().Tables[4];


            DataRow[] drsUserWrite = dt.Select("BrandName = '" + prefixText + "'");

            if (drsUserWrite.Length == 1) //If user write and that item is in database
            {
                HttpContext.Current.Session["UserWriteProductName"] = prefixText;

            }
            else
            {
                HttpContext.Current.Session["UserWriteProductName"] = prefixText;
            }


            DataRow[] drs = dt.Select("BrandName LIKE '%" + prefixText + "%'");

            int counter = 0;
            foreach (DataRow dr in drs)
            {
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["BrandName"].ToString(), dr["BrandName"].ToString()));


                if (++counter >= count) { break; }
            }

            return items.ToArray();
        }

        [WebMethod]
        public static string[] AutoComplete_FillProduct(string prefixText, int count, string contextKey)
        {
            //contextKey is brandCode


            string filter = "ProductName LIKE '%" + prefixText + "%'";

            //get brand 

            if (contextKey != null && contextKey != "" && contextKey != "0")
            {
                filter += " AND BrandCode = " + contextKey;
            }

            if (count == 0) { count = 10; }
            List<string> items = new List<string>(count);

            DataTable dt = GetLookupDataSet().Tables[8];

            DataRow[] drs = dt.Select(filter);

            int counter = 0;
            foreach (DataRow dr in drs)
            {
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["ProductName"].ToString(), dr["ProductName"].ToString()));


                if (++counter >= count) { break; }
            }

            return items.ToArray();
        }

        [WebMethod]
        public static string[] AutoComplete_FillVersion(string prefixText, int count, string contextKey)
        {
            //contextKey is brandCode


            string filter = "ProdVersionName LIKE '%" + prefixText + "%'";

            //get brand 

            //if (contextKey != null && contextKey != "" && contextKey != "0")
            //{
            //}

            if (count == 0) { count = 10; }
            List<string> items = new List<string>(count);

            DataTable dt = GetLookupDataSet().Tables[9];

            DataRow[] drs = dt.Select(filter);

            int counter = 0;
            foreach (DataRow dr in drs)
            {
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["ProdVersionName"].ToString(), dr["ProdVersionName"].ToString()));


                if (++counter >= count) { break; }
            }

            return items.ToArray();
        }

        [WebMethod]
        public static string[] AutoComplete_FillAgency(string prefixText, int count)
        {
            if (count == 0) { count = 10; }
            List<string> items = new List<string>(count);

            DataTable dt = GetLookupDataSet().Tables[2];

            DataRow[] drs = dt.Select("AgencyName LIKE '%" + prefixText + "%'");

            int counter = 0;
            foreach (DataRow dr in drs)
            {
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["AgencyName"].ToString(), dr["AgencyCode"].ToString()));


                if (++counter >= count) { break; }
            }

            return items.ToArray();
        }




        #endregion


        #region Fill Media

        private void FillMediaTypes()
        {

            //lstMediaType.DataSource = GetLookupDataSet().Tables["MediaType"];
            //lstMediaType.DataBind(); 

            //lstMediaType.Items.Remove(lstMediaType.Items.FindByText("Press"));
            //lstMediaType.Items.Remove(lstMediaType.Items.FindByText("Outdoor"));

            ////lstMediaType.Items.Insert(0, new ListItem("All", "0"));

            //Utility.SelectListItemByText(lstMediaType, "TV");

            FillMedia();
        }

        private void FillMedia()
        {

            lstMedia_TV.DataSource = new DataView(GetLookupDataSet().Tables["Media"], "MediaTypeCode=" + Enums.MediaType.TV.GetHashCode(), "MediaName", DataViewRowState.OriginalRows);
            lstMedia_TV.DataBind();


            lstMedia_Radio.DataSource = new DataView(GetLookupDataSet().Tables["Media"], "MediaTypeCode=" + Enums.MediaType.RADIO.GetHashCode(), "MediaName", DataViewRowState.OriginalRows);
            lstMedia_Radio.DataBind();


            lstMedia_Cable.DataSource = new DataView(GetLookupDataSet().Tables["Media"], "MediaTypeCode=" + Enums.MediaType.CABLE.GetHashCode(), "MediaName", DataViewRowState.OriginalRows);
            lstMedia_Cable.DataBind();


            lstMedia_Press.DataSource = new DataView(GetLookupDataSet().Tables["Media"], "MediaTypeCode=" + Enums.MediaType.PRESS.GetHashCode(), "MediaName", DataViewRowState.OriginalRows);
            lstMedia_Press.DataBind();


            lstMedia_OutDoor.DataSource = new DataView(GetLookupDataSet().Tables["Media"], "MediaTypeCode=" + Enums.MediaType.OUTDOOR.GetHashCode(), "MediaName", DataViewRowState.OriginalRows);
            lstMedia_OutDoor.DataBind();

            lstMedia_Internet.DataSource = new DataView(GetLookupDataSet().Tables["Media"], "MediaTypeCode=" + Enums.MediaType.INTERNET.GetHashCode(), "MediaName", DataViewRowState.OriginalRows);
            lstMedia_Internet.DataBind();

            lstMedia_CountrySide.DataSource = new DataView(GetLookupDataSet().Tables["Media"], "MediaTypeCode=" + Enums.MediaType.COUNTRYSIDE.GetHashCode(), "MediaName", DataViewRowState.OriginalRows);
            lstMedia_CountrySide.DataBind();
            lstMedia_CountrySideOutDoor.DataSource = new DataView(GetLookupDataSet().Tables["Media"], "MediaTypeCode=" + Enums.MediaType.COUNTRYSIDEOUTDOOR.GetHashCode(), "MediaName", DataViewRowState.OriginalRows);
            lstMedia_CountrySideOutDoor.DataBind();
        }

        #endregion


        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {

            //-----------------Alerts Start----------------------------------------------------------------------

            // Competition
            if (lstMediaType.SelectedItem.Value == 1.ToString() && lstCategory.SelectedItem.Text == "- ALL -")
            {
                AjaxFuncs.MsgBox(this.Page,
                                "Please select the category.");
                return;
            }

            //Multimedia
            DownloadOnly = chkDownload.Checked;
            if (lstMediaType.SelectedItem.Value == 0.ToString() && DownloadOnly && (lstCategory.SelectedItem.Text == "- ALL -"))
            {
                AjaxFuncs.MsgBox(this.Page,
                                 "To download all the videos, audios, or images related to your category, you must select the category.");
                return;
            }

            DownloadOnlyAdvertiser = chkDownloadAdvertiser.Checked;
            if (lstMediaType.SelectedItem.Value == 0.ToString() && DownloadOnlyAdvertiser && (lstAdvertiser.SelectedItem.Text == "- ALL -"))
            {
                AjaxFuncs.MsgBox(this.Page,
                                 "To download all the videos, audios, or images related to your advertiser, you must select the advertiser.");
                return;
            }


            //-----------------Alerts End---------------------------------------------------------------------------------

            //------------------------Common Start------------------------------------------------
            bool tmp1 = DateTime.TryParse(calS.SelectedDate.ToShortDateString(), out sDate);
            bool tmp2 = DateTime.TryParse(calE.SelectedDate.ToShortDateString(), out eDate);

            if (sDate < Utility.ToDateTime("01/01/2000"))
                sDate = Utility.ToDateTime("01/01/2000");

            if (eDate < Utility.ToDateTime("01/01/2000"))
                eDate = Utility.ToDateTime("01/01/2000");

            if ((sDate.ToString() != "1/1/2000 12:00:00 AM") && (eDate.ToString() != "1/1/2000 12:00:00 AM"))
            {


                mediaTypeCode = 0;

                foreach (ListItem itm in lstMedia_TV.Items)
                {
                    if (itm.Selected)
                        mediaCodes_TV += itm.Value + ",";
                }
                mediaCodes_TV = mediaCodes_TV.TrimEnd(',');


                foreach (ListItem itm in lstMedia_Radio.Items)
                {
                    if (itm.Selected)
                        mediaCodes_Radio += itm.Value + ",";
                }
                mediaCodes_Radio = mediaCodes_Radio.TrimEnd(',');


                foreach (ListItem itm in lstMedia_Cable.Items)
                {
                    if (itm.Selected)
                        mediaCodes_Cable += itm.Value + ",";
                }
                mediaCodes_Cable = mediaCodes_Cable.TrimEnd(',');


                foreach (ListItem itm in lstMedia_Press.Items)
                {
                    if (itm.Selected)
                        mediaCodes_Press += itm.Value + ",";
                }
                mediaCodes_Press = mediaCodes_Press.TrimEnd(',');


                foreach (ListItem itm in lstMedia_Internet.Items)
                {
                    if (itm.Selected)
                        mediaCodes_Internet += itm.Value + ",";
                }
                mediaCodes_Internet = mediaCodes_Internet.TrimEnd(',');


                foreach (ListItem itm in lstMedia_OutDoor.Items)
                {
                    if (itm.Selected)
                        mediaCodes_Outdoor += itm.Value + ",";
                }
                mediaCodes_Outdoor = mediaCodes_Outdoor.TrimEnd(',');


                Session["SearchMediaCodes_TV"] = mediaCodes_TV;
                Session["SearchMediaCodes_RD"] = mediaCodes_Radio;
                Session["SearchMediaCodes_CB"] = mediaCodes_Cable;
                Session["SearchMediaCodes_PR"] = mediaCodes_Press;
                Session["SearchMediaCodes_IN"] = mediaCodes_Internet;
                Session["SearchMediaCodes_OD"] = mediaCodes_Outdoor;


                sectorCode = lstSector.SelectedValue;
                subSectorCode = lstSubSector.SelectedValue;

                categoryCode = lstCategory.SelectedValue;
                //---------------------------Common End----------------------------------------------------------
                if (!chkppt.Checked)
                {
                    if (lstMediaType.SelectedItem.Value == 0.ToString()) // Multimedia
                    {


                        advertiserCode = lstAdvertiser.SelectedValue;

                        if (acBrand.SelectedValue == "0") //not selected by user
                        {
                            if (!String.IsNullOrEmpty(Session["UserWriteProductName"].ToString()))
                            {

                                brandCode = Session["UserWriteProductName"].ToString();
                            }
                        }
                        else
                        {
                            brandCode = acBrand.SelectedValue == "0" ? "" : acBrand.SelectedValue;
                        }

                        DownloadOnlyProduct = chkDownloadProduct.Checked;
                        if (DownloadOnlyProduct && (brandCode == ""))
                        {
                            AjaxFuncs.MsgBox(this.Page,
                                             "To download all the videos, audios, or images related to your product, u must select the product.");
                            return;
                        }


                        productCode = acProduct.SelectedValue == "0" ? "" : acProduct.SelectedValue;
                        versionCode = acVersion.SelectedValue == "0" ? "" : acVersion.SelectedValue;
                        agencyCode = lstAgency.SelectedValue;

                        sTime = Utility.ToInt(lstStartTime.SelectedValue);
                        eTime = Utility.ToInt(lstEndTime.SelectedValue);


                        sPrice = tbPriceFrom.Text != "" ? Utility.ToInt(tbPriceFrom.Text) : 0;
                        ePrice = tbPriceTo.Text != "" ? Utility.ToInt(tbPriceTo.Text) : 0;
                        int DateS = DateTimeToInt(sDate);
                        int DateE = DateTimeToInt(eDate);
                        firstAppearanceOnly = chkFirstAppearance.Checked;
                        Response.Redirect(Server.UrlPathEncode(string.Format("report-all.aspx?sd={0}&ed={1}&mcTV={2}&mcRD={3}&mcCB={4}&mcPR={5}&mcOD={6}&s={7}&ss={8}&cc={9}&adv={10}&brnd={11}&prod={12}&ver={13}&agn={14}&st={15}&et={16}&sp={17}&ep={18}&fa={19}&mcIN={20}&down={21}&downpro={22}&downadv={23}", DateS, DateE, chkAll_TV.Checked, chkAll_Radio.Checked, chkAll_Cable.Checked, chkAll_Press.Checked, chkAll_OutDoor.Checked, sectorCode, subSectorCode, categoryCode, advertiserCode, brandCode, productCode, versionCode, agencyCode, sTime, eTime, sPrice, ePrice, firstAppearanceOnly, chkAll_Internet.Checked, DownloadOnly, DownloadOnlyProduct, DownloadOnlyAdvertiser)));

                    }
                    else //Competition
                    {
                        if (chkCompetition.Checked == true) // if checked means ALL Brands
                        {
                            foreach (ListItem itm in chkLstCompetition.Items)
                            {
                                mediaCodes_Competition += itm.Value + ",";
                            }
                        }
                        else // user to select brands
                        {
                            foreach (ListItem itm in chkLstCompetition.Items)
                            {
                                if (itm.Selected)
                                    mediaCodes_Competition += itm.Value + ",";
                            }
                        }

                        if (chkAdvertiser.Checked == true) // if checked means ALL Advertiser
                        {
                            foreach (ListItem itm in ChkAdvertiserList.Items)
                            {
                                mediaCodes_Competition += itm.Value + ",";
                            }
                        }
                        else // user to select brands
                        {
                            foreach (ListItem itm in ChkAdvertiserList.Items)
                            {
                                if (itm.Selected)
                                    mediaCodes_Competition += itm.Value + ",";
                            }
                        }

                        mediaCodes_Competition = mediaCodes_Competition.TrimEnd(',');
                        Session["SearchMediaCodes_Competition"] = mediaCodes_Competition;

                        // pnlUpdate_ReportAllFilters.Update();
                        Response.Redirect(Server.UrlPathEncode(string.Format("report-competition.aspx?sd={0}&ed={1}&mcTV={2}&mcRD={3}&mcCB={4}&mcPR={5}&mcOD={6}&s={7}&ss={8}&cc={9}&mcIN={10}&cComp={11}",
                        sDate.ToShortDateString().Replace("/", "_"), eDate.ToShortDateString().Replace("/", "_"), chkAll_TV.Checked, chkAll_Radio.Checked, chkAll_Cable.Checked, chkAll_Press.Checked, chkAll_OutDoor.Checked, sectorCode, subSectorCode, categoryCode, chkAll_Internet.Checked, chkCompetition.Checked)));
                    }
                }
                else
                {
                    DownloadOnly = chkDownload.Checked;
                    if (lstMediaType.SelectedItem.Value == 0.ToString() && DownloadOnly && (lstCategory.SelectedItem.Text == "- ALL -"))
                    {
                        AjaxFuncs.MsgBox(this.Page,
                                         "To download all the videos, audios, or images related to your category, you must select the category.");
                        return;
                    }

                    DownloadOnlyAdvertiser = chkDownloadAdvertiser.Checked;
                    if (lstMediaType.SelectedItem.Value == 0.ToString() && DownloadOnlyAdvertiser && (lstAdvertiser.SelectedItem.Text == "- ALL -"))
                    {
                        AjaxFuncs.MsgBox(this.Page,
                                         "To download all the videos, audios, or images related to your advertiser, you must select the advertiser.");
                        return;
                    }
                    DownloadOnlyProduct = chkDownloadProduct.Checked;
                    if (DownloadOnlyProduct && (brandCode == ""))
                    {
                        AjaxFuncs.MsgBox(this.Page,
                                         "To download all the videos, audios, or images related to your product, u must select the product.");
                        return;
                    }
                    Header hdr = new Header();
                    hdr.Category = lstCategory.SelectedItem.Text;
                    string mediaType = string.Empty;
                    if (chkAll_TV.Checked)
                    {
                        mediaType = "TV,";
                        mediaTypeCodes = Enums.MediaType.TV.GetHashCode().ToString() + ",";
                    }
                    if (chkAll_Radio.Checked)
                    {
                        mediaType += "Radio,";
                        mediaTypeCodes += Enums.MediaType.RADIO.GetHashCode().ToString() + ",";
                    }
                    if (chkAll_Press.Checked)
                    {
                        mediaType += "Press,";
                        mediaTypeCodes += Enums.MediaType.PRESS.GetHashCode().ToString() + ",";
                    }
                    if (chkAll_Cable.Checked)
                    {
                        mediaType += "Cable,";
                        mediaTypeCodes += Enums.MediaType.CABLE.GetHashCode().ToString() + ",";
                    }
                    if (chkAll_CountrySideOutDoor.Checked)
                    {
                        mediaType += "CountrySide OutDoor,";
                        // mediaTypeCodes += Enums.MediaType.COUNTRYSIDEOUTDOOR.GetHashCode().ToString() + ",";
                    }
                    if (chkAll_Internet.Checked)
                    {
                        mediaType += "Internet,";
                        mediaTypeCodes += Enums.MediaType.INTERNET.GetHashCode().ToString() + ",";
                    }
                    if (chkAll_OutDoor.Checked)
                    {
                        mediaType += "OutDoor";
                        mediaTypeCodes += Enums.MediaType.OUTDOOR.GetHashCode().ToString() + ",";
                    }
                    hdr.MediaType = mediaType;
                    if (sDate < Utility.ToDateTime("01/01/2000"))
                        sDate = Utility.ToDateTime("01/01/2000");
                    if (eDate < Utility.ToDateTime("01/01/2000"))
                        eDate = Utility.ToDateTime("01/01/2000");
                    hdr.PeriodFrom = sDate;
                    hdr.PeriodTo = eDate;
                    hdr.Sector = lstSector.SelectedItem.Text;
                    hdr.UserID = Convert.ToInt32(Session["UserID"]);
                    hdr.SubSector = lstSubSector.SelectedItem.Text;
                    hdr.Save();

                    string[] singleMediaTypeName = mediaType.TrimEnd(',').Split(',');
                    for (int i = 0; i < singleMediaTypeName.Length; i++)
                    {
                        SPs.AdverTiserfotPPTCount(Convert.ToInt32(Session["UserID"]), DateTimeToInt(sDate), DateTimeToInt(eDate), sDate, eDate, "", lstSector.SelectedItem.Text == "- ALL -" ? "" : lstSector.SelectedItem.Text, lstSubSector.SelectedItem.Text == "- ALL -" ? "" : lstSubSector.SelectedItem.Text, lstCategory.SelectedItem.Text == "- ALL -" ? "" : lstCategory.SelectedItem.Text, lstAdvertiser.SelectedItem.Text == "- ALL -" ? "" : lstAdvertiser.SelectedItem.Text, "", "", lstAgency.SelectedItem.Text == "- ALL -" ? "" : lstAgency.SelectedItem.Text, singleMediaTypeName[i].ToString()).Execute();
                        SPs.CountrecordsfotPPT(Convert.ToInt32(Session["UserID"]), DateTimeToInt(sDate), DateTimeToInt(eDate), sDate, eDate, "", lstSector.SelectedItem.Text == "- ALL -" ? "" : lstSector.SelectedItem.Text, lstSubSector.SelectedItem.Text == "- ALL -" ? "" : lstSubSector.SelectedItem.Text, lstCategory.SelectedItem.Text == "- ALL -" ? "" : lstCategory.SelectedItem.Text, lstAdvertiser.SelectedItem.Text == "- ALL -" ? "" : lstAdvertiser.SelectedItem.Text, "", "", lstAgency.SelectedItem.Text == "- ALL -" ? "" : lstAgency.SelectedItem.Text, singleMediaTypeName[i].ToString()).Execute();
                        SPs.SummaryPPTCount(Convert.ToInt32(Session["UserID"]), DateTimeToInt(sDate), DateTimeToInt(eDate), sDate, eDate, "", lstSector.SelectedItem.Text == "- ALL -" ? "" : lstSector.SelectedItem.Text, lstSubSector.SelectedItem.Text == "- ALL -" ? "" : lstSubSector.SelectedItem.Text, lstCategory.SelectedItem.Text == "- ALL -" ? "" : lstCategory.SelectedItem.Text, lstAdvertiser.SelectedItem.Text == "- ALL -" ? "" : lstAdvertiser.SelectedItem.Text, "", "", lstAgency.SelectedItem.Text == "- ALL -" ? "" : lstAgency.SelectedItem.Text, singleMediaTypeName[i].ToString()).Execute();
                        SPs.MediaTypeInfoPPT(Convert.ToInt32(Session["UserID"]), DateTimeToInt(sDate), DateTimeToInt(eDate), sDate, eDate, "", lstSector.SelectedItem.Text == "- ALL -" ? "" : lstSector.SelectedItem.Text, lstSubSector.SelectedItem.Text == "- ALL -" ? "" : lstSubSector.SelectedItem.Text, lstCategory.SelectedItem.Text == "- ALL -" ? "" : lstCategory.SelectedItem.Text, lstAdvertiser.SelectedItem.Text == "- ALL -" ? "" : lstAdvertiser.SelectedItem.Text, "", "", lstAgency.SelectedItem.Text == "- ALL -" ? "" : lstAgency.SelectedItem.Text, singleMediaTypeName[i].ToString()).Execute();
                        SPs.Versionppt(Convert.ToInt32(Session["UserID"]), DateTimeToInt(sDate), DateTimeToInt(eDate), sDate, eDate, "", lstSector.SelectedItem.Text == "- ALL -" ? "" : lstSector.SelectedItem.Text, lstSubSector.SelectedItem.Text == "- ALL -" ? "" : lstSubSector.SelectedItem.Text, lstCategory.SelectedItem.Text == "- ALL -" ? "" : lstCategory.SelectedItem.Text, lstAdvertiser.SelectedItem.Text == "- ALL -" ? "" : lstAdvertiser.SelectedItem.Text, "", "", lstAgency.SelectedItem.Text == "- ALL -" ? "" : lstAgency.SelectedItem.Text, singleMediaTypeName[i].ToString()).Execute();
                        SPs.WeeksPPT(Convert.ToInt32(Session["UserID"]), DateTimeToInt(sDate), DateTimeToInt(eDate), sDate, eDate, "", lstSector.SelectedItem.Text == "- ALL -" ? "" : lstSector.SelectedItem.Text, lstSubSector.SelectedItem.Text == "- ALL -" ? "" : lstSubSector.SelectedItem.Text, lstCategory.SelectedItem.Text == "- ALL -" ? "" : lstCategory.SelectedItem.Text, lstAdvertiser.SelectedItem.Text == "- ALL -" ? "" : lstAdvertiser.SelectedItem.Text, "", "", lstAgency.SelectedItem.Text == "- ALL -" ? "" : lstAgency.SelectedItem.Text, singleMediaTypeName[i].ToString()).Execute();
                    }
                    //lblJavaScript.Text = "<script type='text/javascript'>ShowHideDiv(document.getElementById('dvUploading'), false);</script>"; 
                    //System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "document.getElementById('dvUploading').style.display='none';", true); 
                    //button1.Enabled = false;
                    bool IsEmbedded = true;
                    //label1.Text = "";
                    int slideCount = 0;
                    try
                    {
                        DataSet ds = SPs.SelectDataForPPT(Convert.ToInt32(Session["UserID"])).GetDataSet();
                        string category = string.Empty, period = string.Empty, Mediatype = string.Empty;
                        DateTime periodfrom = DateTime.MinValue, periodto = DateTime.MinValue;
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            category = Convert.ToString(ds.Tables[0].Rows[0]["Category"]).Replace("\r", "").Replace("\n", "").ToUpper();
                            periodfrom = Convert.ToDateTime(ds.Tables[0].Rows[0]["Period from"]);
                            periodto = Convert.ToDateTime(ds.Tables[0].Rows[0]["Period to"]);
                            period = periodfrom.ToString("MMMM d yyyy").ToUpper() + " - " + periodto.ToString("MMMM d yyyy").ToUpper();
                            Mediatype = Convert.ToString(ds.Tables[0].Rows[0]["Media type"]);
                            Mediatype = Mediatype.Replace("\r", "").Replace("\n", "");
                        }
                        using (PresentationEx pres = new PresentationEx())
                        {
                            //Adding Empty slide
                            SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 1.pptx"));
                            SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 2.pptx"));
                            pres.Slides.Remove(pres.Slides[0]);
                            tvTable = ds.Tables[2].Select("Media_type='TV'").Count() > 0 ? ds.Tables[2].Select("Media_type='TV'").CopyToDataTable() : null;
                            cableTable = ds.Tables[2].Select("Media_type='Cable'").Count() > 0 ? ds.Tables[2].Select("Media_type='Cable'").CopyToDataTable() : null;
                            countryRadioTable = ds.Tables[2].Select("Media_type='Country Side Radio'").Count() > 0 ? ds.Tables[2].Select("Media_type='Country Side Radio'").CopyToDataTable() : null;
                            pressTable = ds.Tables[2].Select("Media_type='Press'").Count() > 0 ? ds.Tables[2].Select("Media_type='Press'").CopyToDataTable() : null;
                            outdoorTable = ds.Tables[2].Select("Media_type='Outdoor'").Count() > 0 ? ds.Tables[2].Select("Media_type='Outdoor'").CopyToDataTable() : null;
                            countyOutdoorTable = ds.Tables[2].Select("Media_type='CountrySide Outdoor'").Count() > 0 ? ds.Tables[2].Select("Media_type='CountrySide Outdoor'").CopyToDataTable() : null;
                            radioTable = ds.Tables[2].Select("Media_type='Radio'").Count() > 0 ? ds.Tables[2].Select("Media_type='Radio'").CopyToDataTable() : null;
                            internetTable = ds.Tables[2].Select("Media_type='Internet'").Count() > 0 ? ds.Tables[2].Select("Media_type='Internet'").CopyToDataTable() : null;
                            advertiserTable = ds.Tables[3];
                            dowTable = ds.Tables[4];
                            weeksTable = ds.Tables[6];
                            versionTable = ds.Tables[5];
                            templateTable = ds.Tables[7];
                            if (templateTable.Rows.Count == 0)
                            {
                                templateTable.Rows.Add(2, 10, "Template 1.pptx", "Template 2.pptx", "Template 3.pptx", "Template 4.pptx", "Template 5.pptx", "Template 6.pptx", "", "", "TV_Small.png", "TV_Big.png", "Cable_small.png", "Cable_Big.png", "Radio_small.png", "Radio_Big.png", "Radio_int_small.png", "Radio_int_big.png", "Outdoor_Small.png", "Outdoor_Big.png", "Outdoor_Int_small.png", "Ootdoor_Int_Big.png", "Internet_big.png", "Internet_small.png", "Press_Big.png", "Press_small.png");

                            }

                            if (tvTable != null && tvTable.Rows.Count > 0)
                            {
                                slideCount = slideCount + 2;
                                screenPos.Add("TV", slideCount);
                                ClonePPT(pres, "TV", slideCount);
                                slideCount = slideCount + 6;
                                if (versionTable.Select("[Media type]='TV'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='TV'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 5.pptx"));
                                        slideCount++;
                                    }
                                }
                            }
                            if (cableTable != null && cableTable.Rows.Count > 0)
                            {
                                screenPos.Add("Cable", slideCount);
                                ClonePPT(pres, "Cable", slideCount);
                                slideCount = slideCount + 6;
                                if (versionTable.Select("[Media type]='Cable'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Cable'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 5.pptx"));
                                        slideCount++;
                                    }
                                }
                            }
                            if (radioTable != null && radioTable.Rows.Count > 0)
                            {
                                screenPos.Add("Radio", slideCount);
                                ClonePPT(pres, "Radio", slideCount);
                                slideCount = slideCount + 6;
                                if (versionTable.Select("[Media type]='Radio'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Radio'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 5.pptx"));
                                        slideCount++;
                                    }
                                }
                            }
                            if (countryRadioTable != null && countryRadioTable.Rows.Count > 0)
                            {
                                screenPos.Add("Country Side Radio", slideCount);
                                ClonePPT(pres, "Country Side Radio", slideCount);
                                slideCount = slideCount + 6;
                                if (versionTable.Select("[Media type]='Country Side Radio'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Country Side Radio'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 5.pptx"));
                                        slideCount++;
                                    }
                                }
                            }
                            if (pressTable != null && pressTable.Rows.Count > 0)
                            {
                                screenPos.Add("Press", slideCount);
                                ClonePPT(pres, "Press", slideCount);
                                slideCount = slideCount + 6;
                                if (versionTable.Select("[Media type]='Press'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Press'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 5.pptx"));
                                        slideCount++;
                                    }
                                }
                            }
                            if (internetTable != null && internetTable.Rows.Count > 0)
                            {
                                screenPos.Add("Internet", slideCount);
                                ClonePPT(pres, "Internet", slideCount);
                                slideCount = slideCount + 6;
                                if (versionTable.Select("[Media type]='Internet'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Internet'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 5.pptx"));
                                        slideCount++;
                                    }
                                }
                            }

                            if (outdoorTable != null && outdoorTable.Rows.Count > 0)
                            {
                                screenPos.Add("Outdoor", slideCount);
                                ClonePPT(pres, "Outdoor", slideCount);
                                slideCount = slideCount + 6;
                                if (versionTable.Select("[Media type]='Outdoor'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Outdoor'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 5.pptx"));
                                        slideCount++;
                                    }
                                }
                            }
                            if (countyOutdoorTable != null && countyOutdoorTable.Rows.Count > 0)
                            {
                                screenPos.Add("CountrySide Outdoor", slideCount);
                                ClonePPT(pres, "CountrySide Outdoor", slideCount);
                                slideCount = slideCount + 6;
                                if (versionTable.Select("[Media type]='CountrySide Outdoor'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='CountrySide Outdoor'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 5.pptx"));
                                        slideCount++;
                                    }
                                }
                            }
                            SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 6.pptx"));

                            slideCount = 0;
                            PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 2.8), (int)(pres.SlideSize.Size.Height / 2.6), (int)(pres.SlideSize.Size.Width * .65), 130, 34, Color.FromArgb(0, 176, 240), "REPORTE DE INSERCIONES,INVERSION Y  COMERCIALES", TextAlignmentEx.Right, true);

                            lstProp = new List<TextProperties>();
                            lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(182, 182, 185), Text = "CATEGORIA: " });
                            lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = category.ToUpper() });

                            PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 2.5), (int)(pres.SlideSize.Size.Height / 1.58), (int)(pres.SlideSize.Size.Width * .6), 40, 20, lstProp, TextAlignmentEx.Right, true);

                            lstProp = new List<TextProperties>();
                            lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(182, 182, 185), Text = "PERIODO: " });
                            lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = period.ToUpper() });

                            PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 2.5), (int)(pres.SlideSize.Size.Height / 1.45), (int)(pres.SlideSize.Size.Width * .6), 30, 16, lstProp, TextAlignmentEx.Right, true);
                            int MediaCount = Mediatype.Split(',').Count();
                            int range = (MediaCount % 2 == 0) ? (MediaCount / 2) : (MediaCount / 2) + 1;
                            PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 2.15), (int)(pres.SlideSize.Size.Height / 1.32), 85, 40, 16, Color.FromArgb(182, 182, 185), "MEDIOS:", TextAlignmentEx.Right, true);
                            PPTText.CreateMediaBulletList(pres, slideCount, (int)(pres.SlideSize.Size.Width / 1.75), (int)(pres.SlideSize.Size.Height / 1.23), 100, range * 5, Mediatype.Split(',').ToList().GetRange(0, range), 16, Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), TextAlignmentEx.Left, false, screenPos);
                            PPTText.CreateMediaBulletList(pres, slideCount, (int)(pres.SlideSize.Size.Width / 1.45), (int)(pres.SlideSize.Size.Height / 1.23), 215, (MediaCount - range) * 5, Mediatype.Split(',').ToList().GetRange(range, MediaCount - range), 16, Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), TextAlignmentEx.Left, false, screenPos);
                            //PPTText.CreateTextBoxWithHyperlink(pres, slideCount, (int)(pres.SlideSize.Size.Width / 1.58), (int)(pres.SlideSize.Size.Height / 1.345), 230, 40, 16, Color.FromArgb(215, 0, 54), Mediatype.Replace(",", " - "), "MOVE TO TELEVISON SLIDE", TextAlignmentEx.Left);
                            ImageUtilities.RemoveShapeBorder(pres, slideCount);
                            slideCount++;
                            // second slide
                            PPTText.CreateTextBox(pres, slideCount, 0, 40, (int)(pres.SlideSize.Size.Width), 30, 30, Color.FromArgb(0, 157, 217), "RESUMEN", TextAlignmentEx.Center, false);
                            PPTText.CreateTextBox(pres, slideCount, 0, 72, (int)(pres.SlideSize.Size.Width), 20, 18, Color.FromArgb(0, 157, 217), category, TextAlignmentEx.Center, true);
                            PPTText.CreateTextBox(pres, slideCount, 0, 92, (int)(pres.SlideSize.Size.Width), 20, 18, Color.FromArgb(0, 157, 217), period, TextAlignmentEx.Center, true);
                            PPTTable.AddTableWithLink(pres, slideCount, 40, (int)(pres.SlideSize.Size.Height / 3.7), 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), ds.Tables[1], screenPos);
                            AddAllIcons(pres);
                            if (tvTable != null && tvTable.Rows.Count > 0)
                            {
                                // third slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width - 380), (int)(pres.SlideSize.Size.Height / 1.93), 370, 40, 32, Color.FromArgb(0, 157, 217), "TELEVISION", TextAlignmentEx.Right, true);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 4.2), (int)(pres.SlideSize.Size.Height / 1.7), (int)(pres.SlideSize.Size.Width * .75), 30, 24, Color.FromArgb(0, 157, 217), category, TextAlignmentEx.Right, false);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 1.78), (int)(pres.SlideSize.Size.Height / 1.55), 300, 30, 20, Color.FromArgb(0, 157, 217), period, TextAlignmentEx.Right, true);

                                // fourth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 40, 32, Color.FromArgb(0, 157, 217), "TELEVISION INSERCIONES E INVERSION", TextAlignmentEx.Left, true);
                                lstProp = new List<TextProperties>();
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "Categoría : " });
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = category.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 40, 90, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                lstProp1 = new List<TextProperties>();
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "  Período : " });
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = period.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 35, 120, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                List<string> ListItems = new List<string>();
                                ListItems.Add("Inversión e Inserciones por Medio.");
                                ListItems.Add("Inversión e Inserciones por Anunciante.");
                                ListItems.Add("Inversión e Inserciones por Día.");
                                ListItems.Add("Inversión e Inserciones por Semana");
                                ListItems.Add("Versiones");
                                PPTText.CreateBulletList(pres, slideCount, 40, 150, (int)(pres.SlideSize.Size.Width / 1.1), 200, ListItems, 24, Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), TextAlignmentEx.Left, false, screenPos.Where(x => x.Key == "TV").FirstOrDefault().Value);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // fifth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "TELEVISION INS & INV POR MEDIO", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                newTable = tvTable.Copy();
                                newTable.Columns.Remove("Media_type");
                                newTable.AcceptChanges();
                                PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);


                                // sixth slide
                                slideCount++;
                                if (advertiserTable.Select("[Media type]='TV'").Count() > 0)
                                {
                                    newTable = advertiserTable.Select("[Media type]='TV'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "TELEVISION INS & INV POR ANUNCIANTE", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);


                                slideCount++;
                                if (dowTable.Select("[Media type]='TV'").Count() > 0)
                                {
                                    newTable = dowTable.Select("[Media type]='TV'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }

                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "TELEVISION INS & INV POR DIA SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (weeksTable.Select("[Media type]='TV'").Count() > 0)
                                {
                                    newTable = weeksTable.Select("[Media type]='TV'").CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "TELEVISION POR SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // ninth slide
                                if (versionTable.Select("[Media type]='TV'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='TV'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        slideCount++;
                                        PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "TELEVISION Versiones", TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                        EmbedMedia.AddVideo(pres, slideCount, 30, 150, 320, 320, Server.MapPath("../videos/" + Convert.ToString(dr["Clip"]).Replace("\r", "").Replace("\n", "")), Server.MapPath("../videos/" + Convert.ToString(dr["Image"]).Replace("\r", "").Replace("\n", "")), IsEmbedded);
                                        PPTTable.AddVersionTable(pres, slideCount, (int)(pres.SlideSize.Size.Width - 350), 140, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), dr, "TV");
                                        ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                    }
                                }

                            }


                            if (cableTable != null && cableTable.Rows.Count > 0)
                            {
                                // third slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width - 380), (int)(pres.SlideSize.Size.Height / 1.93), 370, 40, 32, Color.FromArgb(0, 157, 217), "TELEVISION PAGA", TextAlignmentEx.Right, true);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 4.2), (int)(pres.SlideSize.Size.Height / 1.7), (int)(pres.SlideSize.Size.Width * .75), 30, 24, Color.FromArgb(0, 157, 217), category, TextAlignmentEx.Right, false);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 1.78), (int)(pres.SlideSize.Size.Height / 1.55), 300, 30, 20, Color.FromArgb(0, 157, 217), period, TextAlignmentEx.Right, true);

                                // fourth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 40, 32, Color.FromArgb(0, 157, 217), "TV PAGA INSERCIONES E INVERSIÓN", TextAlignmentEx.Left, true);
                                lstProp = new List<TextProperties>();
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "Categoría : " });
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = category.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 40, 90, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                lstProp1 = new List<TextProperties>();
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "  Período : " });
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = period.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 35, 120, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                List<string> ListItems = new List<string>();
                                ListItems.Add("Inversión e Inserciones por Medio.");
                                ListItems.Add("Inversión e Inserciones por Anunciante.");
                                ListItems.Add("Inversión e Inserciones por Día.");
                                ListItems.Add("Inversión e Inserciones por Semana");
                                ListItems.Add("Versiones");
                                PPTText.CreateBulletList(pres, slideCount, 40, 130, (int)(pres.SlideSize.Size.Width / 1.1), 200, ListItems, 24, Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), TextAlignmentEx.Left, false, screenPos.Where(x => x.Key == "Cable").FirstOrDefault().Value);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // fifth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "TV PAGA INS & INV POR MEDIO", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                newTable = cableTable.Copy();
                                newTable.Columns.Remove("Media_type");
                                newTable.AcceptChanges();
                                PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);

                                newTable.Dispose();
                                // sixth slide

                                slideCount++;
                                if (advertiserTable.Select("[Media type]='Cable'").Count() > 0)
                                {
                                    newTable = advertiserTable.Select("[Media type]='Cable'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "TV PAGA INS & INV POR ANUNCIANTE", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (dowTable.Select("[Media type]='Cable'").Count() > 0)
                                {
                                    newTable = dowTable.Select("[Media type]='Cable'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }

                                // seventh slide
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "TV PAGA INS & INV POR DIA SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (weeksTable.Select("[Media type]='Cable'").Count() > 0)
                                {
                                    newTable = weeksTable.Select("[Media type]='Cable'").CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);

                                }
                                // eight slide

                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "TV PAGA POR SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // ninth slide
                                if (versionTable.Select("[Media type]='Cable'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Cable'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        slideCount++;
                                        PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "Television PAGA Versiones", TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                        EmbedMedia.AddVideo(pres, slideCount, 30, 150, 320, 320, Server.MapPath("../radio/" + Convert.ToString(dr["Clip"]).Replace("\r", "").Replace("\n", "")), Server.MapPath("../radio/" + Convert.ToString(dr["Image"]).Replace("\r", "").Replace("\n", "")), IsEmbedded);
                                        PPTTable.AddVersionTable(pres, slideCount, (int)(pres.SlideSize.Size.Width - 350), 140, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), dr, "Cable");
                                        ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                    }
                                }
                            }

                            if (radioTable != null && radioTable.Rows.Count > 0)
                            {
                                // third slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width - 380), (int)(pres.SlideSize.Size.Height / 1.93), 370, 40, 32, Color.FromArgb(0, 157, 217), "RADIO LOCAL", TextAlignmentEx.Right, true);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 4.2), (int)(pres.SlideSize.Size.Height / 1.7), (int)(pres.SlideSize.Size.Width * .75), 30, 24, Color.FromArgb(0, 157, 217), category, TextAlignmentEx.Right, false);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 1.78), (int)(pres.SlideSize.Size.Height / 1.55), 300, 30, 20, Color.FromArgb(0, 157, 217), period, TextAlignmentEx.Right, true);

                                // fourth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 40, 32, Color.FromArgb(0, 157, 217), "RADIO LOCAL INSERCIONES E INVERSIÓN", TextAlignmentEx.Left, true);
                                lstProp = new List<TextProperties>();
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "Categoría : " });
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = category.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 40, 90, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                lstProp1 = new List<TextProperties>();
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "  Período : " });
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = period.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 35, 120, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                List<string> ListItems = new List<string>();
                                ListItems.Add("Inversión e Inserciones por Medio.");
                                ListItems.Add("Inversión e Inserciones por Anunciante.");
                                ListItems.Add("Inversión e Inserciones por Día.");
                                ListItems.Add("Inversión e Inserciones por Semana");
                                ListItems.Add("Versiones");
                                PPTText.CreateBulletList(pres, slideCount, 40, 130, (int)(pres.SlideSize.Size.Width / 1.1), 200, ListItems, 24, Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), TextAlignmentEx.Left, false, screenPos.Where(x => x.Key == "Radio").FirstOrDefault().Value);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // fifth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "RADIO LOCAL INS & INV POR MEDIO", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                newTable = radioTable.Copy();
                                newTable.Columns.Remove("Media_type");
                                newTable.AcceptChanges();
                                PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);


                                // sixth slide
                                slideCount++;
                                if (advertiserTable.Select("[Media type]='Radio'").Count() > 0)
                                {
                                    newTable = advertiserTable.Select("[Media type]='Radio'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "RADIO LOCAL INS & INV POR ANUNCIANTE", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (dowTable.Select("[Media type]='Radio'").Count() > 0)
                                {
                                    newTable = dowTable.Select("[Media type]='Radio'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                // seventh slide
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "RADIO LOCAL INS & INV POR DIA SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (weeksTable.Select("[Media type]='Radio'").Count() > 0)
                                {
                                    newTable = weeksTable.Select("[Media type]='Radio'").CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }

                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "RADIO LOCAL POR SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // ninth slide
                                if (versionTable.Select("[Media type]='Radio'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Radio'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        slideCount++;
                                        PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "RADIO LOCAL Versiones", TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                        EmbedMedia.AddVideo(pres, slideCount, 30, 150, 320, 320, Server.MapPath("../radio/" + Convert.ToString(dr["Clip"]).Replace("\r", "").Replace("\n", "")), Server.MapPath("../radio/" + Convert.ToString(dr["Image"]).Replace("\r", "").Replace("\n", "")), IsEmbedded);
                                        PPTTable.AddVersionTable(pres, slideCount, (int)(pres.SlideSize.Size.Width - 350), 140, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), dr, "Radio");
                                        ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                    }
                                }
                            }

                            if (countryRadioTable != null && countryRadioTable.Rows.Count > 0)
                            {
                                // third slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width - 380), (int)(pres.SlideSize.Size.Height / 1.93), 370, 40, 32, Color.FromArgb(0, 157, 217), "RADIO INTERIOR", TextAlignmentEx.Right, true);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 4.2), (int)(pres.SlideSize.Size.Height / 1.7), (int)(pres.SlideSize.Size.Width * .75), 30, 24, Color.FromArgb(0, 157, 217), category, TextAlignmentEx.Right, false);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 1.78), (int)(pres.SlideSize.Size.Height / 1.55), 300, 30, 20, Color.FromArgb(0, 157, 217), period, TextAlignmentEx.Right, true);

                                // fourth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 40, 32, Color.FromArgb(0, 157, 217), "RADIO INTERIOR INSERCIONES E INVERSIÓN", TextAlignmentEx.Left, true);
                                lstProp = new List<TextProperties>();
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "Categoría : " });
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = category.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 40, 90, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                lstProp1 = new List<TextProperties>();
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "  Período : " });
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = period.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 35, 120, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                List<string> ListItems = new List<string>();
                                ListItems.Add("Inversión e Inserciones por Medio.");
                                ListItems.Add("Inversión e Inserciones por Anunciante.");
                                ListItems.Add("Inversión e Inserciones por Día.");
                                ListItems.Add("Inversión e Inserciones por Semana");
                                ListItems.Add("Versiones");
                                PPTText.CreateBulletList(pres, slideCount, 40, 130, (int)(pres.SlideSize.Size.Width / 1.1), 200, ListItems, 24, Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), TextAlignmentEx.Left, false, screenPos.Where(x => x.Key == "Country Side Radio").FirstOrDefault().Value);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // fifth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "RADIO INTERIOR INS & INV POR MEDIO", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                newTable = countryRadioTable.Copy();
                                newTable.Columns.Remove("Media_type");
                                newTable.AcceptChanges();
                                PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);


                                // sixth slide
                                slideCount++;
                                if (advertiserTable.Select("[Media type]='Country Side Radio'").Count() > 0)
                                {
                                    newTable = advertiserTable.Select("[Media type]='Country Side Radio'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "RADIO INTERIOR INS & INV POR ANUNCIANTE", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (dowTable.Select("[Media type]='Country Side Radio'").Count() > 0)
                                {
                                    newTable = dowTable.Select("[Media type]='Country Side Radio'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }


                                // seventh slide
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "RADIO INTERIOR INS & INV POR DIA SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (weeksTable.Select("[Media type]='Country Side Radio'").Count() > 0)
                                {
                                    newTable = weeksTable.Select("[Media type]='Country Side Radio'").CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }

                                // eight slide
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "RADIO INTERIOR POR SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // ninth slide
                                if (versionTable.Select("[Media type]='Country Side Radio'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Country Side Radio'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        slideCount++;
                                        PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "RADIO INTERIOR Versiones", TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                        EmbedMedia.AddVideo(pres, slideCount, 30, 150, 320, 320, Server.MapPath("../radio/" + Convert.ToString(dr["Clip"]).Replace("\r", "").Replace("\n", "")), Server.MapPath("../radio/" + Convert.ToString(dr["Image"]).Replace("\r", "").Replace("\n", "")), IsEmbedded);
                                        PPTTable.AddVersionTable(pres, slideCount, (int)(pres.SlideSize.Size.Width - 350), 140, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), dr, "Country Side Radio");
                                        ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                    }
                                }
                            }

                            if (pressTable != null && pressTable.Rows.Count > 0)
                            {
                                // third slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width - 380), (int)(pres.SlideSize.Size.Height / 1.93), 370, 40, 32, Color.FromArgb(0, 157, 217), "PRENSA", TextAlignmentEx.Right, true);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 4.2), (int)(pres.SlideSize.Size.Height / 1.7), (int)(pres.SlideSize.Size.Width * .75), 30, 24, Color.FromArgb(0, 157, 217), category, TextAlignmentEx.Right, false);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 1.78), (int)(pres.SlideSize.Size.Height / 1.55), 300, 30, 20, Color.FromArgb(0, 157, 217), period, TextAlignmentEx.Right, true);

                                // fourth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 40, 32, Color.FromArgb(0, 157, 217), "PRENSA INSERCIONES E INVERSIÓN", TextAlignmentEx.Left, true);
                                lstProp = new List<TextProperties>();
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "Categoría : " });
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = category.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 40, 90, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                lstProp1 = new List<TextProperties>();
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "  Período : " });
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = period.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 35, 120, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                List<string> ListItems = new List<string>();
                                ListItems.Add("Inversión e Inserciones por Medio.");
                                ListItems.Add("Inversión e Inserciones por Anunciante.");
                                ListItems.Add("Inversión e Inserciones por Día.");
                                ListItems.Add("Inversión e Inserciones por Semana");
                                ListItems.Add("Versiones");
                                PPTText.CreateBulletList(pres, slideCount, 40, 130, (int)(pres.SlideSize.Size.Width / 1.1), 200, ListItems, 24, Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), TextAlignmentEx.Left, false, screenPos.Where(x => x.Key == "Press").FirstOrDefault().Value);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // fifth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "PRENSA INS & INV POR MEDIO", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                newTable = pressTable.Copy();
                                newTable.Columns.Remove("Media_type");
                                newTable.AcceptChanges();
                                PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);


                                // sixth slide
                                slideCount++;
                                if (advertiserTable.Select("[Media type]='Press'").Count() > 0)
                                {
                                    newTable = advertiserTable.Select("[Media type]='Press'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "PRENSA INS & INV POR ANUNCIANTE", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (dowTable.Select("[Media type]='Press'").Count() > 0)
                                {
                                    newTable = dowTable.Select("[Media type]='Press'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);

                                }


                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "PRENSA INS & INV POR DIA SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);


                                slideCount++;
                                if (weeksTable.Select("[Media type]='Press'").Count() > 0)
                                {
                                    newTable = weeksTable.Select("[Media type]='Press'").CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }

                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "PRENSA POR SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // ninth slide
                                if (versionTable.Select("[Media type]='Press'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Press'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        slideCount++;
                                        PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "PRENSA Versiones", TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                        EmbedMedia.AddVideo(pres, slideCount, 30, 150, 320, 320, Server.MapPath("../press/" + Convert.ToString(dr["Clip"]).Replace("\r", "").Replace("\n", "")), Server.MapPath("../press/" + Convert.ToString(dr["Image"]).Replace("\r", "").Replace("\n", "")), IsEmbedded);
                                        PPTTable.AddVersionTable(pres, slideCount, (int)(pres.SlideSize.Size.Width - 350), 140, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), dr, "Press");
                                        ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                    }
                                }

                            }


                            if (internetTable != null && internetTable.Rows.Count > 0)
                            {
                                // third slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width - 380), (int)(pres.SlideSize.Size.Height / 1.93), 370, 40, 32, Color.FromArgb(0, 157, 217), "INTERNET", TextAlignmentEx.Right, true);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 4.2), (int)(pres.SlideSize.Size.Height / 1.7), (int)(pres.SlideSize.Size.Width * .75), 30, 24, Color.FromArgb(0, 157, 217), category, TextAlignmentEx.Right, false);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 1.78), (int)(pres.SlideSize.Size.Height / 1.55), 300, 30, 20, Color.FromArgb(0, 157, 217), period, TextAlignmentEx.Right, true);

                                // fourth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 40, 32, Color.FromArgb(0, 157, 217), "INTERNET INSERCIONES E INVERSIÓN ", TextAlignmentEx.Left, true);
                                lstProp = new List<TextProperties>();
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "Categoría : " });
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = category.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 40, 90, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                lstProp1 = new List<TextProperties>();
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "  Período : " });
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = period.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 35, 120, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                List<string> ListItems = new List<string>();
                                ListItems.Add("Inversión e Inserciones por Medio.");
                                ListItems.Add("Inversión e Inserciones por Anunciante.");
                                ListItems.Add("Inversión e Inserciones por Día.");
                                ListItems.Add("Inversión e Inserciones por Semana");
                                ListItems.Add("Versiones");
                                PPTText.CreateBulletList(pres, slideCount, 40, 130, (int)(pres.SlideSize.Size.Width / 1.1), 200, ListItems, 24, Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), TextAlignmentEx.Left, false, screenPos.Where(x => x.Key == "Internet").FirstOrDefault().Value);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // fifth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "INTERNET INTERIOR INS & INV POR MEDIO", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                newTable = internetTable.Copy();
                                newTable.Columns.Remove("Media_type");
                                newTable.AcceptChanges();
                                PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);


                                // sixth slide
                                slideCount++;
                                if (advertiserTable.Select("[Media type]='Internet'").Count() > 0)
                                {
                                    newTable = advertiserTable.Select("[Media type]='Internet'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "INTERNET INTERIOR INS & INV POR ANUNCIANTE", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (dowTable.Select("[Media type]='Internet'").Count() > 0)
                                {
                                    newTable = dowTable.Select("[Media type]='Internet'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }

                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "INTERNET INTERIOR INS & INV POR DIA SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (weeksTable.Select("[Media type]='Internet'").Count() > 0)
                                {
                                    newTable = weeksTable.Select("[Media type]='Internet'").CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }

                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "INTERNET INTERIOR POR SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // ninth slide
                                if (versionTable.Select("[Media type]='Internet'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Internet'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        slideCount++;
                                        PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "INTERNET", TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                        EmbedMedia.AddVideo(pres, slideCount, 30, 150, 320, 320, Server.MapPath("../internet/" + Convert.ToString(dr["Clip"]).Replace("\r", "").Replace("\n", "")), Server.MapPath("../internet/" + Convert.ToString(dr["Image"]).Replace("\r", "").Replace("\n", "")), IsEmbedded);
                                        PPTTable.AddVersionTable(pres, slideCount, (int)(pres.SlideSize.Size.Width - 350), 140, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), dr, "Internet");
                                        ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                    }
                                }

                            }



                            if (outdoorTable != null && outdoorTable.Rows.Count > 0)
                            {
                                // third slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width - 380), (int)(pres.SlideSize.Size.Height / 1.93), 370, 40, 32, Color.FromArgb(0, 157, 217), "OUTDOOR", TextAlignmentEx.Right, true);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 4.2), (int)(pres.SlideSize.Size.Height / 1.7), (int)(pres.SlideSize.Size.Width * .75), 30, 24, Color.FromArgb(0, 157, 217), category, TextAlignmentEx.Right, false);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 1.78), (int)(pres.SlideSize.Size.Height / 1.55), 300, 30, 20, Color.FromArgb(0, 157, 217), period, TextAlignmentEx.Right, true);

                                // fourth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 40, 32, Color.FromArgb(0, 157, 217), "OUTDOOR INSERCIONES E INVERSIÓN", TextAlignmentEx.Left, true);
                                lstProp = new List<TextProperties>();
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "Categoría : " });
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = category.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 40, 90, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                lstProp1 = new List<TextProperties>();
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "  Período : " });
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = period.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 35, 120, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                List<string> ListItems = new List<string>();
                                ListItems.Add("Inversión e Inserciones por Medio.");
                                ListItems.Add("Inversión e Inserciones por Anunciante.");
                                ListItems.Add("Inversión e Inserciones por Día.");
                                ListItems.Add("Inversión e Inserciones por Semana");
                                ListItems.Add("Versiones");
                                PPTText.CreateBulletList(pres, slideCount, 40, 130, (int)(pres.SlideSize.Size.Width / 1.1), 200, ListItems, 24, Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), TextAlignmentEx.Left, false, screenPos.Where(x => x.Key == "Outdoor").FirstOrDefault().Value);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // fifth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "OUTDOOR INS & INV POR MEDIO", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                newTable = outdoorTable.Copy();
                                newTable.Columns.Remove("Media_type");
                                newTable.AcceptChanges();
                                PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);


                                // sixth slide
                                slideCount++;
                                if (advertiserTable.Select("[Media type]='Outdoor'").Count() > 0)
                                {
                                    newTable = advertiserTable.Select("[Media type]='Outdoor'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "OUTDOOR INS & INV POR ANUNCIANTE", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (dowTable.Select("[Media type]='Outdoor'").Count() > 0)
                                {
                                    newTable = dowTable.Select("[Media type]='Outdoor'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "OUTDOOR INS & INV POR DIA SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);



                                slideCount++;
                                if (weeksTable.Select("[Media type]='Outdoor'").Count() > 0)
                                {
                                    newTable = weeksTable.Select("[Media type]='Outdoor'").CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "OUTDOOR POR SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // ninth slide

                                if (versionTable.Select("[Media type]='Outdoor'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='Outdoor'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        slideCount++;
                                        PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "OUTDOOR Versiones", TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                        EmbedMedia.AddVideo(pres, slideCount, 30, 150, 320, 320, Server.MapPath("../outdoor/" + Convert.ToString(dr["Clip"]).Replace("\r", "").Replace("\n", "")), Server.MapPath("../outdoor/" + Convert.ToString(dr["Image"]).Replace("\r", "").Replace("\n", "")), IsEmbedded);
                                        PPTTable.AddVersionTable(pres, slideCount, (int)(pres.SlideSize.Size.Width - 350), 140, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), dr, "Outdoor");
                                        ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                    }
                                }


                            }


                            if (countyOutdoorTable != null && countyOutdoorTable.Rows.Count > 0)
                            {
                                // third slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width - 380), (int)(pres.SlideSize.Size.Height / 1.93), 370, 40, 32, Color.FromArgb(0, 157, 217), "OUTDOOR INTERIOR", TextAlignmentEx.Right, true);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 4.2), (int)(pres.SlideSize.Size.Height / 1.7), (int)(pres.SlideSize.Size.Width * .75), 30, 24, Color.FromArgb(0, 157, 217), category, TextAlignmentEx.Right, false);
                                PPTText.CreateTextBox(pres, slideCount, (int)(pres.SlideSize.Size.Width / 1.78), (int)(pres.SlideSize.Size.Height / 1.55), 300, 30, 20, Color.FromArgb(0, 157, 217), period, TextAlignmentEx.Right, true);

                                // fourth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 40, 32, Color.FromArgb(0, 157, 217), "OUTDOOR INT. INSERCIONES E INVERSIÓN", TextAlignmentEx.Left, true);
                                lstProp = new List<TextProperties>();
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "Categoría : " });
                                lstProp.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = category.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 40, 90, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                lstProp1 = new List<TextProperties>();
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(95, 95, 95), Text = "  Período : " });
                                lstProp1.Add(new TextProperties() { Forecolor = Color.FromArgb(0, 157, 217), Text = period.ToUpper() });
                                PPTText.CreateTextBox(pres, slideCount, 35, 120, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                List<string> ListItems = new List<string>();
                                ListItems.Add("Inversión e Inserciones por Medio.");
                                ListItems.Add("Inversión e Inserciones por Anunciante.");
                                ListItems.Add("Inversión e Inserciones por Día.");
                                ListItems.Add("Inversión e Inserciones por Semana");
                                ListItems.Add("Versiones");
                                PPTText.CreateBulletList(pres, slideCount, 40, 130, (int)(pres.SlideSize.Size.Width / 1.1), 200, ListItems, 24, Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), TextAlignmentEx.Left, false, screenPos.Where(x => x.Key == "CountrySide Outdoor").FirstOrDefault().Value);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // fifth slide
                                slideCount++;
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "OUTDOOR INT. INS & INV POR MEDIO", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                newTable = countyOutdoorTable.Copy();
                                newTable.Columns.Remove("Media_type");
                                newTable.AcceptChanges();
                                PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);


                                // sixth slide
                                slideCount++;
                                if (advertiserTable.Select("[Media type]='CountrySide Outdoor'").Count() > 0)
                                {
                                    newTable = advertiserTable.Select("[Media type]='CountrySide Outdoor'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "OUTDOOR INT. INS & INV POR ANUNCIANTE", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (dowTable.Select("[Media type]='CountrySide Outdoor'").Count() > 0)
                                {
                                    newTable = dowTable.Select("[Media type]='CountrySide Outdoor'").CopyToDataTable();
                                    newTable.Columns.Remove("Media Type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }

                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "OUTDOOR INT. INS & INV POR DIA SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                slideCount++;
                                if (weeksTable.Select("[Media type]='CountrySide Outdoor'").Count() > 0)
                                {

                                    newTable = weeksTable.Select("[Media type]='CountrySide Outdoor'").CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    PPTTable.AddTable(pres, slideCount, 40, 115, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), newTable);
                                }
                                PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "OUTDOOR INT. POR SEMANA", TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                ImageUtilities.RemoveShapeBorder(pres, slideCount);

                                // ninth slide
                                if (versionTable.Select("[Media type]='CountrySide Outdoor'").Count() > 0)
                                {
                                    newTable = versionTable.Select("[Media type]='CountrySide Outdoor'", "Inversión DESC").AsEnumerable().Take(20).CopyToDataTable();
                                    newTable.Columns.Remove("Media type");
                                    newTable.AcceptChanges();
                                    foreach (DataRow dr in newTable.Rows)
                                    {
                                        slideCount++;
                                        PPTText.CreateTextBox(pres, slideCount, 40, 10, (int)(pres.SlideSize.Size.Width - 50), 40, 30, Color.FromArgb(0, 157, 217), "OUTDOOR INT. Versiones", TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 40, 50, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp, TextAlignmentEx.Left, true);
                                        PPTText.CreateTextBox(pres, slideCount, 35, 80, (int)(pres.SlideSize.Size.Width - 50), 30, 18, lstProp1, TextAlignmentEx.Left, true);
                                        EmbedMedia.AddVideo(pres, slideCount, 30, 150, 320, 320, Server.MapPath("../outdoor/" + Convert.ToString(dr["Clip"]).Replace("\r", "").Replace("\n", "")), Server.MapPath("../outdoor/" + Convert.ToString(dr["Image"]).Replace("\r", "").Replace("\n", "")), IsEmbedded);
                                        PPTTable.AddVersionTable(pres, slideCount, (int)(pres.SlideSize.Size.Width - 350), 140, 1, Color.FromArgb(249, 251, 253), Color.FromArgb(0, 157, 217), Color.FromArgb(255, 255, 255), Color.FromArgb(95, 95, 95), dr, "TV");
                                        ImageUtilities.RemoveShapeBorder(pres, slideCount);
                                    }
                                }
                            }
                            pptFilePath = Server.MapPath("~/" + Session["UserName"].ToString() + "_Presentation.pptx");
                            pres.Save(pptFilePath, SaveFormat.Pptx);
                            SPs.DeleteDataOfPpt(Convert.ToInt32(Session["UserID"])).Execute();
                            Session["pptFilePath"] = pptFilePath;
                        }
                    }
                    catch (Exception ex)
                    {
                    }


                    if (DownloadOnly)
                    {
                        DataTable cat = downloadCategory(sDate.ToShortDateString(), eDate.ToShortDateString(), mediaTypeCodes.TrimEnd(','), lstCategory.SelectedValue.ToString());
                        Session["cat"] = cat;

                    }
                    if (DownloadOnlyAdvertiser)
                    {
                        DataTable ad = downloadAdvetisers(sDate.ToShortDateString(), eDate.ToShortDateString(), mediaTypeCodes.TrimEnd(','), lstAdvertiser.SelectedValue.ToString());
                        Session["ad"] = ad;

                    }
                    if (DownloadOnlyProduct)
                    {
                        DataTable prod = downloadProduct(sDate.ToShortDateString(), eDate.ToShortDateString(), mediaTypeCodes.TrimEnd(','), acBrand.SelectedValue.ToString());
                        Session["prod"] = prod;

                    }
                    string url = Utility.AppPath + "/downLoadPPT.aspx";

                    StringBuilder sb = new StringBuilder();

                    sb.Append("<script type = 'text/javascript'>");

                    sb.Append("window.open('");

                    sb.Append(url);

                    sb.Append("');");

                    sb.Append("</script>");

                    ClientScript.RegisterStartupScript(this.GetType(),

                            "script", sb.ToString());



                }
            }
            else
            {
                string script = "alert(\"Please select date first!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }

        protected void lstMediaType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstMediaType.SelectedItem.Value == 0.ToString()) //Multimedia
            {
                pnlforMultimedia.Visible = true;
            }
            else //Competition
            {
                pnlforMultimedia.Visible = false;
            }
            //pnlUpdate_ReportAllFilters.Update();
        }

        protected void lstCategory_SelectedIndexChanged(object sender, EventArgs e)
        {


            if (lstMediaType.SelectedItem.Value != 0.ToString()) //Competition
            {
                if (!String.IsNullOrEmpty(lstCategory.SelectedItem.Value))
                {
                    BindBrandsAccordingtoCategories(lstCategory.SelectedItem.Value);
                }

                if (lstCategory.SelectedItem.Value == "") // if user select ALL
                {
                    chkLstCompetition.Items.Clear();
                    chkLstCompetition.DataSource = null;
                    chkLstCompetition.DataBind();
                }


                PnlCompetitionBrands.Visible = true;
            }
            else
            {
                PnlCompetitionBrands.Visible = false;
            }

        }

        private void BindBrandsAccordingtoCategories(String SelectedCategory)
        {
            DataTable dt = RfController.GetCompetitionBrands_CategoryName(SelectedCategory);
            if (dt.Rows.Count > 0)
            {
                chkLstCompetition.DataSource = dt;
                chkLstCompetition.DataBind();
            }
            DataTable dtAdvretisers = RfController.GetCompetitionAdvertisers_CategoryName(SelectedCategory);
            if (dtAdvretisers.Rows.Count > 0)
            {
                ChkAdvertiserList.DataSource = dtAdvretisers;
                ChkAdvertiserList.DataBind();
            }
        }

        protected void chkCompetition_CheckedChanged(object sender, EventArgs e)
        {
            divAdvertisersList.Visible = false;
            for (int i = 0; i < ChkAdvertiserList.Items.Count; i++)
            {
                ChkAdvertiserList.Items[i].Selected = false;
            }

            if (chkAdvertiser.Checked)
            {
                lblErrorMsg.Visible = true;
                lblErrorMsg.Text = "Only one choice can be made at a time.";
                chkAdvertiser.Checked = false;

            }
            else
            {

                if (chkCompetition.Checked)
                    divCompetition.Visible = false;
                else
                    divCompetition.Visible = true;
            }
        }

        protected void chkAdvertiser_CheckedChanged(object sender, EventArgs e)
        {
            divCompetition.Visible = false;
            divCompetition.Visible = false;
            for (int i = 0; i < chkLstCompetition.Items.Count; i++)
            {
                chkLstCompetition.Items[i].Selected = false;
            }
            if (chkCompetition.Checked)
            {
                lblErrorMsg.Visible = true;
                lblErrorMsg.Text = "Only one choice can be made at a time.";
                chkCompetition.Checked = false;

            }
            else
            {
                lblErrorMsg.Visible = false;
                if (chkAdvertiser.Checked)
                    divAdvertisersList.Visible = false;
                else
                    divAdvertisersList.Visible = true;
            }
        }

        public static int DateTimeToInt(DateTime theDate)
        {
            string month = theDate.Month.ToString();
            string Day = theDate.Day.ToString();
            month = (month.Length < 2) ? "0" + month : month;
            Day = (Day.Length < 2) ? "0" + Day : Day;
            int date = Convert.ToInt32(theDate.Year.ToString() + month.ToString() + Day.ToString());
            return date;
        }

        public DataTable downloadCategory(string sd, string ed, string mediaTypeCodes, string cc)
        {
            int sDate = DateTimeToInt(Convert.ToDateTime(sd));
            int eDate = DateTimeToInt(Convert.ToDateTime(ed));
            Int32 checkResponse = 0;
            DataTable table = new DataTable();
            table.Columns.Add("CatName", typeof(string));
            table.Columns.Add("filePath", typeof(string));
            //ZipFile zip = new ZipFile();
            string[] mtc = mediaTypeCodes.Split(',');
            for (int i = 0; i < mtc.Length; i++)
            {

                Int32 MediaType = 0;
                String CName = String.Empty;
                String CategoryName = String.Empty;

                try
                {

                    MediaType = Convert.ToInt32(mtc[i].ToString());
                    CName = cc;


                }
                catch
                {

                }
                DataTable dt = RfController.GetVideosAudiosCategoryName2(MediaType, CName, sDate, eDate);

                if (dt.Rows.Count > 0)
                {
                    #region[Zip Format]

                    String filePath = String.Empty;
                    String filePath1 = String.Empty;

                    String downloadFileName = String.Empty;
                    downloadFileName = dt.Rows[0]["CategoryName"].ToString().Replace("/", "") + ".zip";
                    downloadFileName = downloadFileName.Replace(" ", "_");
                    //if (checkResponse == 0)
                    //{
                    //    Response.Clear();
                    //    // no buffering - allows large zip files to download as they are zipped
                    //    Response.BufferOutput = false;
                    //    Response.ContentType = "application/zip";
                    //    Response.AddHeader("content-disposition", "filename=" + downloadFileName);
                    //}
                    checkResponse = 1;

                    //using (zip = new ZipFile())
                    //{
                    foreach (DataRow row in dt.Rows)
                    {
                        String filePathCheck = String.Empty;
                        String filePathCheck1 = String.Empty;

                        String CatName = String.Empty;


                        if (MediaType.ToString() == "1") //TV
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["CategoryName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../videos/" + filePath);
                        }

                        else if ((MediaType.ToString() == "3") || (MediaType.ToString() == "5")) //RADIO AND CABLE
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["CategoryName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../radio/" + filePath);
                        }

                        else if (MediaType.ToString() == "6") //press
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["CategoryName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../press/" + filePath);
                        }
                        else if (MediaType.ToString() == "7") //outdoor
                        {
                            filePath = row["NewOutDoorFile"].ToString();
                            filePath1 = row["StreetGraph"].ToString();
                            CatName = row["CategoryName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../outdoor/" + filePath);
                            filePathCheck1 = Server.MapPath("../outdoor-street/" + filePath1);
                        }
                        else if (MediaType.ToString() == "8")//News
                        {
                            filePath = row["CropPicture"].ToString();
                            filePath1 = row["FullPagePicture"].ToString();
                            CatName = row["CategoryName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../news/Cropped/" + filePath);
                            filePathCheck1 = Server.MapPath("../news/FullPage/" + filePath1);
                        }
                        else if (MediaType.ToString() == "9") //internet
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["CategoryName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../internet/" + filePath);
                        }


                        if (filePath != "")
                        {
                            if (File.Exists(filePathCheck))
                            {
                                //try
                                //{
                                //if (!zip.ContainsEntry(CatName + "/" + filePath))
                                //{
                                if (!table.AsEnumerable().Any(x => CatName == x.Field<String>("CatName")))

                                    table.Rows.Add(CatName, filePathCheck);
                                //zip.AddFile(filePathCheck, CatName);
                                //}
                                //}
                                //catch { }
                            }
                        }

                        if (filePath1 != "")
                        {
                            if (File.Exists(filePathCheck1))
                            {
                                //try
                                //{
                                //if (!zip.ContainsEntry(CatName + "/" + filePath1))
                                //{
                                if (!table.AsEnumerable().Any(x => CatName == x.Field<String>("CatName")))
                                    table.Rows.Add(CatName, filePathCheck1);
                                //zip.AddFile(filePathCheck1, CatName);
                                //}
                                //}
                                //catch { }
                            }
                        }
                    }
                    //zip.Save(Response.OutputStream);
                    //}

                    #endregion
                }


            } //Foreach end

            return table;
        }

        public DataTable downloadAdvetisers(string sd, string ed, string mediaTypeCodes, string adv)
        {
            //Int32 checkResponse = 0;
            DataTable table = new DataTable();
            table.Columns.Add("CatName", typeof(string));
            table.Columns.Add("filePath", typeof(string));

            //ZipFile zip = new ZipFile();
            string[] mtc = mediaTypeCodes.Split(',');
            for (int i = 0; i < mtc.Length; i++)
            {
                Int32 MediaType = 0;
                String CName = String.Empty;
                String CategoryName = String.Empty;

                try
                {

                    MediaType = Convert.ToInt32(mtc[i].ToString());
                    CName = adv;


                }
                catch
                {

                }
                DataTable dt = RfController.GetVideosAudiosAdvertiserName(MediaType, CName);
                String filePath = String.Empty;
                String filePath1 = String.Empty;
                if (dt.Rows.Count > 0)
                {
                    #region[Zip Format]



                    //String downloadFileName = String.Empty;
                    //downloadFileName = dt.Rows[0]["AdvertiserName"].ToString().Replace("/", "") + ".zip";
                    //downloadFileName = downloadFileName.Replace(" ", "_");

                    //if (checkResponse == 0)
                    //{
                    //    Response.Clear();
                    //    // no buffering - allows large zip files to download as they are zipped
                    //    Response.BufferOutput = false;
                    //    Response.ContentType = "application/zip";
                    //    Response.AddHeader("content-disposition", "filename=" + downloadFileName);
                    //}
                    //checkResponse = 1;
                    //using (zip = new ZipFile())
                    //{
                    foreach (DataRow row in dt.Rows)
                    {
                        String filePathCheck = String.Empty;
                        String filePathCheck1 = String.Empty;

                        String CatName = String.Empty;


                        if (MediaType.ToString() == "1") //TV
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["AdvertiserName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../videos/" + filePath);
                        }

                        else if ((MediaType.ToString() == "3") || (MediaType.ToString() == "5")) //RADIO AND CABLE
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["AdvertiserName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../radio/" + filePath);
                        }

                        else if (MediaType.ToString() == "6") //press
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["AdvertiserName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../press/" + filePath);
                        }
                        else if (MediaType.ToString() == "7") //outdoor
                        {
                            filePath = row["NewOutDoorFile"].ToString();
                            filePath1 = row["StreetGraph"].ToString();
                            CatName = row["AdvertiserName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../outdoor/" + filePath);
                            filePathCheck1 = Server.MapPath("../outdoor-street/" + filePath1);
                        }
                        else if (MediaType.ToString() == "8")//News
                        {
                            filePath = row["CropPicture"].ToString();
                            filePath1 = row["FullPagePicture"].ToString();
                            CatName = row["AdvertiserName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../news/Cropped/" + filePath);
                            filePathCheck1 = Server.MapPath("../news/FullPage/" + filePath1);
                        }
                        else if (MediaType.ToString() == "9") //internet
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["AdvertiserName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../internet/" + filePath);
                        }


                        if (filePath != "")
                        {
                            if (File.Exists(filePathCheck))
                            {
                                //try
                                //{

                                if (!table.AsEnumerable().Any(x => CatName == x.Field<String>("CatName")))

                                    table.Rows.Add(CatName, filePathCheck);


                                //}
                                //catch { }
                            }
                        }

                        if (filePath1 != "")
                        {
                            if (File.Exists(filePathCheck1))
                            {
                                //try
                                //{
                                if (!table.AsEnumerable().Any(x => CatName == x.Field<String>("CatName")))
                                    table.Rows.Add(CatName, filePathCheck1);
                                //}
                                //catch { }
                            }
                        }
                    }
                    //zip.Save(Response.OutputStream);
                    //}

                    #endregion
                }


            } //Foreach end

            //zip.Save(Response.OutputStream);
            //Response.Close();
            //Response.End();
            return table;
        }

        public DataTable downloadProduct(string sd, string ed, string mediaTypeCodes, string brand)
        {
            Int32 checkResponse = 0;

            // ZipFile zip = new ZipFile();
            DataTable table = new DataTable();
            table.Columns.Add("CatName", typeof(string));
            table.Columns.Add("filePath", typeof(string));
            string[] mtc = mediaTypeCodes.Split(',');
            for (int i = 0; i < mtc.Length; i++)
            {

                Int32 MediaType = 0;
                String CName = String.Empty;
                String CategoryName = String.Empty;

                try
                {

                    MediaType = Convert.ToInt32(mtc[i].ToString());
                    CName = brand;


                }
                catch
                {

                }
                DataTable dt = RfController.GetVideosAudiosProductName(MediaType, CName);
                String filePath = String.Empty;
                String filePath1 = String.Empty;
                if (dt.Rows.Count > 0)
                {
                    #region[Zip Format]



                    //String downloadFileName = String.Empty;
                    //String downloadFileName_ = String.Empty;
                    //downloadFileName_ = dt.Rows[0]["BrandName"].ToString().Replace("/", "") + ".zip";
                    //downloadFileName = downloadFileName_.Replace(" ", "_");


                    //// no buffering - allows large zip files to download as they are zipped
                    //if (checkResponse == 0)
                    //{
                    //    Response.Clear();
                    //    Response.BufferOutput = false;

                    //    Response.ContentType = "application/zip";
                    //    Response.AddHeader("content-disposition", "filename=" + downloadFileName);
                    //}
                    //checkResponse = 1;


                    //using (zip = new ZipFile())
                    //{



                    foreach (DataRow row in dt.Rows)
                    {
                        String filePathCheck = String.Empty;
                        String filePathCheck1 = String.Empty;

                        String CatName = String.Empty;


                        if (MediaType.ToString() == "1") //TV
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["BrandName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../videos/" + filePath);
                        }

                        else if ((MediaType.ToString() == "3") || (MediaType.ToString() == "5")) //RADIO AND CABLE
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["BrandName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../radio/" + filePath);
                        }

                        else if (MediaType.ToString() == "6") //press
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["BrandName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../press/" + filePath);
                        }
                        else if (MediaType.ToString() == "7") //outdoor
                        {
                            filePath = row["NewOutDoorFile"].ToString();
                            filePath1 = row["StreetGraph"].ToString();
                            CatName = row["BrandName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../outdoor/" + filePath);
                            filePathCheck1 = Server.MapPath("../outdoor-street/" + filePath1);
                        }
                        else if (MediaType.ToString() == "8")//News
                        {
                            filePath = row["CropPicture"].ToString();
                            filePath1 = row["FullPagePicture"].ToString();
                            CatName = row["BrandName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../news/Cropped/" + filePath);
                            filePathCheck1 = Server.MapPath("../news/FullPage/" + filePath1);
                        }
                        else if (MediaType.ToString() == "9") //internet
                        {
                            filePath = row["DFile"].ToString();
                            CatName = row["BrandName"].ToString().Replace("/", "");
                            CatName = CatName.Replace(" ", "_"); ;
                            filePathCheck = Server.MapPath("../internet/" + filePath);
                        }


                        if (filePath != "")
                        {
                            if (File.Exists(filePathCheck))
                            {
                                //try
                                //{
                                if (!table.AsEnumerable().Any(x => CatName == x.Field<String>("CatName")))
                                    table.Rows.Add(CatName, filePathCheck);
                                //}
                                //catch { }
                            }
                        }

                        if (filePath1 != "")
                        {
                            if (File.Exists(filePathCheck1))
                            {
                                //try
                                //{
                                if (!table.AsEnumerable().Any(x => CatName == x.Field<String>("CatName")))
                                    table.Rows.Add(CatName, filePathCheck1);
                                //catch { }
                            }
                        }
                    }
                    #endregion
                }
            } //Foreach end

            return table;
        }
        private void ClonePPT(PresentationEx pres, string Category, int SlidePos)
        {
            SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 3.pptx"));
            string ImagePath = string.Empty;
            if (Category == "TV")
                ImagePath = Server.MapPath("../Image/TV_Small.png");
            else if (Category == "Cable")
                ImagePath = Server.MapPath("../Image/Cable_small.png");
            else if (Category == "Radio")
                ImagePath = Server.MapPath("../Image/Radio_Small.png");
            else if (Category == "Country Side Radio")
                ImagePath = Server.MapPath("../Image/Radio_int_small.png");
            else if (Category == "Press")
                ImagePath = Server.MapPath("../Image/Press_small.png");
            else if (Category == "Internet")
                ImagePath = Server.MapPath("../Image/Internet_small.png");
            else if (Category == "Outdoor")
                ImagePath = Server.MapPath("../Image/Outdoor_small.png");
            else if (Category == "CountrySide Outdoor")
                ImagePath = Server.MapPath("../Image/Outdoor_Int_small.png");
            SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 4.pptx"));
            //AddIcons(pres, Category, SlidePos + 1);
            AddFifthTemplate(pres, ImagePath, SlidePos + 2);
            AddFifthTemplate(pres, ImagePath, SlidePos + 3);
            AddFifthTemplate(pres, ImagePath, SlidePos + 4);
            AddFifthTemplate(pres, ImagePath, SlidePos + 5);
        }
        private void AddFifthTemplate(PresentationEx pres, string ImagePath, int SlidePos)
        {
            SlideFunctions.CloneFromAnotherPPT(pres, Server.MapPath("../Templates/Template 5.pptx"));
            System.Drawing.Image img = (System.Drawing.Image)new Bitmap(ImagePath);
            ImageUtilities.AddPictureFrame(pres, SlidePos, (int)(pres.SlideSize.Size.Width / 1.2), 20, 60, 60, img);
        }

        private void AddAllIcons(PresentationEx pres)
        {
            foreach (KeyValuePair<string, int> pos in screenPos)
                AddIcons(pres, pos.Key, pos.Value + 1);
        }
        private void AddIcons(PresentationEx pres, string Category, int SlidePos)
        {
            System.Drawing.Image img = null;
            int xPosition = 80;
            int screenPosValue = 0;
            if (Category == "TV")
            {
                if (Convert.ToString(templateTable.Rows[0]["TV_Big"]) != "")
                {
                    img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["TV_Big"])));
                    screenPosValue = screenPos.Where(x => x.Key == Category).FirstOrDefault().Value;
                    ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 80, 80, img, screenPosValue);
                    xPosition = xPosition + 90;
                }
            }
            else if (Convert.ToString(templateTable.Rows[0]["TV_Small"]) != "")
            {
                img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["TV_Big"])));
                screenPosValue = screenPos.Where(x => x.Key == "TV").FirstOrDefault().Value;
                ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 60, 60, img, screenPosValue); ;
                xPosition = xPosition + 70;
            }
            if (Category == "Cable")
            {
                if (Convert.ToString(templateTable.Rows[0]["Cable_Big"]) != "")
                {
                    img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Cable_Big"])));
                    screenPosValue = screenPos.Where(x => x.Key == Category).FirstOrDefault().Value;
                    ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 80, 80, img, screenPosValue);
                    xPosition = xPosition + 90;
                }
            }
            else if (Convert.ToString(templateTable.Rows[0]["cable_small"]) != "")
            {
                img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["cable_small"])));
                screenPosValue = screenPos.Where(x => x.Key == "Cable").FirstOrDefault().Value;
                ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 60, 60, img, screenPosValue); ;
                xPosition = xPosition + 70;
            }
            if (Category == "Radio")
            {
                if (Convert.ToString(templateTable.Rows[0]["Radio_Big"]) != "")
                {
                    img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Radio_Big"])));
                    screenPosValue = screenPos.Where(x => x.Key == Category).FirstOrDefault().Value;
                    ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 80, 80, img, screenPosValue);
                    xPosition = xPosition + 90;
                }
            }
            else if (Convert.ToString(templateTable.Rows[0]["Radio_small"]) != "")
            {
                img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Radio_small"])));
                screenPosValue = screenPos.Where(x => x.Key == "Radio").FirstOrDefault().Value;
                ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 60, 60, img, screenPosValue); ;
                xPosition = xPosition + 70;
            }
            if (Category == "Country Side Radio")
            {
                if (Convert.ToString(templateTable.Rows[0]["Radio_Int_Big"]) != "")
                {
                    img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Radio_small"])));
                    screenPosValue = screenPos.Where(x => x.Key == Category).FirstOrDefault().Value;
                    ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 80, 80, img, screenPosValue);
                    xPosition = xPosition + 90;
                }
            }
            else if (Convert.ToString(templateTable.Rows[0]["Radio_Int_small"]) != "")
            {
                img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Radio_Int_small"])));
                screenPosValue = screenPos.Where(x => x.Key == "Country Side Radio").FirstOrDefault().Value;
                ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 60, 60, img, screenPosValue); ;
                xPosition = xPosition + 70;
            }
            if (Category == "Press")
            {
                if (Convert.ToString(templateTable.Rows[0]["Press_Big"]) != "")
                {
                    img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Press_Big"])));
                    screenPosValue = screenPos.Where(x => x.Key == Category).FirstOrDefault().Value;
                    ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 80, 80, img, screenPosValue);
                    xPosition = xPosition + 90;
                }
            }
            else if (Convert.ToString(templateTable.Rows[0]["Press_small"]) != "")
            {
                img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Press_small"])));
                screenPosValue = screenPos.Where(x => x.Key == "Press").FirstOrDefault().Value;
                ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 60, 60, img, screenPosValue); ;
                xPosition = xPosition + 70;
            }
            if (Category == "Internet")
            {
                if (Convert.ToString(templateTable.Rows[0]["Internet_big"]) != "")
                {
                    img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Internet_big"])));
                    screenPosValue = screenPos.Where(x => x.Key == Category).FirstOrDefault().Value;
                    ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 80, 80, img, screenPosValue);
                    xPosition = xPosition + 90;
                }
            }
            else if (Convert.ToString(templateTable.Rows[0]["Internet_small"]) != "")
            {
                img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Internet_small"])));
                screenPosValue = screenPos.Where(x => x.Key == "Internet").FirstOrDefault().Value;
                ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 60, 60, img, screenPosValue); ;
                xPosition = xPosition + 70;
            }
            if (Category == "Outdoor")
            {
                if (Convert.ToString(templateTable.Rows[0]["Outdoor_Big"]) != "")
                {
                    img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Outdoor_Big"])));
                    screenPosValue = screenPos.Where(x => x.Key == Category).FirstOrDefault().Value;
                    ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 80, 80, img, screenPosValue);
                    xPosition = xPosition + 90;
                }
            }
            else if (Convert.ToString(templateTable.Rows[0]["Outdoor_small"]) != "")
            {
                img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Outdoor_small"])));
                screenPosValue = screenPos.Where(x => x.Key == "Outdoor").FirstOrDefault().Value;
                ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 60, 60, img, screenPosValue); ;
                xPosition = xPosition + 70;
            }
            if (Category == "CountrySide Outdoor")
            {
                if (Convert.ToString(templateTable.Rows[0]["Outdoor_Int_Big"]) != "")
                {
                    img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Outdoor_Int_Big"])));
                    screenPosValue = screenPos.Where(x => x.Key == Category).FirstOrDefault().Value;
                    ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 80, 80, img, screenPosValue);
                    xPosition = xPosition + 90;
                }
            }
            else if (Convert.ToString(templateTable.Rows[0]["Outdoor_Int_small"]) != "")
            {
                img = (System.Drawing.Image)new Bitmap(Server.MapPath("../Image/" + Convert.ToString(templateTable.Rows[0]["Outdoor_Int_small"])));
                screenPosValue = screenPos.Where(x => x.Key == "CountrySide Outdoor").FirstOrDefault().Value;
                ImageUtilities.AddPictureFrameWithLink(pres, SlidePos, xPosition, (int)(pres.SlideSize.Size.Height / 1.3), 60, 60, img, screenPosValue); ;
                xPosition = xPosition + 70;
            }
            ImageUtilities.RemoveShapeBorder(pres, SlidePos);
        }

    }
}











